<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List, manager.ManagerBean" %>
<%
	session.setAttribute("stage", "1");
	// リクエスト文字列のエンコードを設定
	request.setCharacterEncoding("UTF-8");
	// パラメータの取得
	Integer crtPage = (Integer)request.getAttribute("page");
	Integer cnt = (Integer)request.getAttribute("cnt");
	String msg = (String)request.getAttribute("msg");
	// ページ表示件数を取得
	int max = ManagerBean.PAGE_MAX;
%>
<jsp:include page="/share/layout.jsp">
    <jsp:param name="title" value="担当者一覧"/>
    <jsp:param name="css" value="manager.css"/>
    <jsp:param name="content">
        <jsp:attribute name="value">
<!-- contents start -->
<% if(msg != null && !"".equals(msg)) { %>
<div id="msg_area">
	<%= msg %>
</div>
<% } %>

<p>担当者を選択して下さい</p>

<form id="mng_form" action="MenuServlet">
	<table class="list_table">
		<tr>
			<th id="id" colspan="2">担当者ID</th>
			<th id="name">担当者名</th>
			<th id="ruby">カナ</th>
			<th id="level">管理者</th>
		</tr>
		<%
		@SuppressWarnings("unchecked")
		List<ManagerBean> list = (List<ManagerBean>)request.getAttribute("list");
		for(int i=0; i<list.size(); i++) {
			ManagerBean manager = list.get(i);
		%>
		<tr <% if(i%2!=0){ out.print("class=\"color\""); } %>>
			<td align="center"><input type="radio" name="id" value="<%= manager.getId() %>" /></td>
			<td align="center"><%= manager.getId() %></td>
			<td><%= manager.getName() %></td>
			<td><%= manager.getRuby() %></td>
			<td align="center"><% if(manager.isUpperLevel()) { %>★<% } %></td>
		</tr>
		<%
		}
		%>
	</table>

	<div id="paging_area">
		<%
			double dMax = cnt / (double)max;
			int maxPage = (int)Math.ceil(dMax);
		%>
		<%= crtPage %> / <%= maxPage %><br />
		<%
			if(maxPage > 1) {
				String linkPage = "/Books/manager/ListServlet?page=";
				if(crtPage > 1) {
					int p = crtPage - 1;
					out.println("<a href=\"" + linkPage + p + "\">前へ</a>");
				}
				for(int i=0, p=1; i<cnt; i+=max, p++) {
					out.println("<a href=\"" + linkPage + p + "\">" + p + "</a>");
				}
				if(crtPage * max < cnt) {
					int p = crtPage + 1;
					out.println("<a href=\"" + linkPage + p + "\">次へ</a>");
				}
			}
		%>
	</div>

	<input class="button" type="submit" name="delete" value="削除" />
	<input class="button" type="submit" name="edit" value="変更" />
	<input class="button" type="submit" name="entry" value="新規登録" />

</form>
<!-- contents end -->
        </jsp:attribute>
    </jsp:param>
</jsp:include>